When a restricted page is accessed, Sitecore will automatically redirect to the login page and pass three parameters - User, Login and Item. The problem is that some restricted pages are accessed with a query string, which is lost when Sitecore redirects to login.html. How is it possible to get access to the original URL or query string?
For example:
Please see the workaround below.
You need to create a custom processor and pass the query string value to the ClientData variable (Sitecore.Context.ClientData). Then you will be able to read this value from the code-behind of your login page.
1. Create your custom class library with the following sample source code:
using System;
using Sitecore;
using Sitecore.Web;
using Sitecore.Pipelines.HttpRequest;
namespace Custom
{
public class QueryStringSaver
{
public void Process(HttpRequestArgs args)
{
// requesting the query string
string querystring = args.QueryString;
// setting the client data value
Sitecore.Context.ClientData.SetValue("qs", querystring);
}
}
}
2. Compile and place it into the bin folder of your Sitecore installation.
Add your custom processor into the <httpRequestBegin> section of the web.config file before the QueryStringResolver processor as shown below:
<httpRequestBegin>
...
<processor type="Custom.QueryStringSaver, QueryStringSaver" />
<processor type="Sitecore.Pipelines.HttpRequest.QueryStringResolver, Sitecore.Kernel" />
...
</httpRequestBegin>
3. Add the following lines to your login layout code:
private void Page_Load(object sender, System.EventArgs e)
{
// getting the query string value
string clientDataQueryString = Sitecore.Context.ClientData.GetValue("qs") as string;
// output
Response.Write(clientDataQueryString);
}
Now the original query string can be preserved.
Note:
It is assumed that the URL of the login page is added into the IgnoreURLPrefixes list of the web.config file as shown below:
<setting name="IgnoreUrlPrefixes" value="/trace.axd|/sitecore/shell/Editor|/sitecore/admin/upgrade/
|UnhandledException.html|/layouts/login.html" />